<?php

namespace common\models\searchs;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\DhNodes;

/**
 * SearchDhNodes represents the model behind the search form about `common\models\DhNodes`.
 */
class SearchDhNodes extends DhNodes
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['NodeID', 'NodeType', 'ParentID','status',  'Depth', 'RootID', 'Child', 'PrevID', 'NextID', 'OrderID', 'ShowOnMenu', 'ShowOnPath', 'ShowOnMap', 'ShowOnList_Index', 'ShowOnList_Parent', 'PurviewType', 'InheritPurviewFromParent', 'WorkFlowID', 'HitsOfHot', 'LeastOfEliteLevel', 'OpenType', 'ItemCount', 'ItemChecked', 'CommentCount', 'IsCreateListPage', 'IsCreateContentPage', 'AutoCreateHtmlType', 'ItemOpenType', 'ItemListOrderType', 'ItemPageSize', 'ListPageSavePathType', 'NeedCreateHtml', 'EnableSubDomain', 'ConfigType', 'IncrementalUpdatePages', 'EnablePhone', 'EnablePad'], 'integer'],
            [['NodeIdentifier', 'ParentPath', 'arrChildID', 'NodeDir', 'ParentDir', 'NodeName', 'Tips', 'Description', 'NodePicUrl', 'Meta_Keywords', 'Meta_Description', 'Creater', 'Custom_Content', 'ContentPageHtmlRule', 'ListPageHtmlRule', 'ItemAspxFileName', 'RelateNode', 'RelateSpecial', 'DefaultTemplateFile', 'ContainChildTemplateFile', 'UpLoadDirRule', 'LinkUrl', 'Settings', 'IPLock', 'ListPagePostFix', 'CultureName', 'SubDomain'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = DhNodes::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'NodeID' => $this->NodeID,
            'NodeType' => $this->NodeType,
            'ParentID' => $this->ParentID,
            'Depth' => $this->Depth,
            'RootID' => $this->RootID,
            'Child' => $this->Child,
            'PrevID' => $this->PrevID,
            'NextID' => $this->NextID,
            'OrderID' => $this->OrderID,
            'ShowOnMenu' => $this->ShowOnMenu,
            'ShowOnPath' => $this->ShowOnPath,
            'ShowOnMap' => $this->ShowOnMap,
            'ShowOnList_Index' => $this->ShowOnList_Index,
            'ShowOnList_Parent' => $this->ShowOnList_Parent,
            'PurviewType' => $this->PurviewType,
            'InheritPurviewFromParent' => $this->InheritPurviewFromParent,
            'WorkFlowID' => $this->WorkFlowID,
            'HitsOfHot' => $this->HitsOfHot,
            'LeastOfEliteLevel' => $this->LeastOfEliteLevel,
            'OpenType' => $this->OpenType,
            'ItemCount' => $this->ItemCount,
            'ItemChecked' => $this->ItemChecked,
            'CommentCount' => $this->CommentCount,
            'IsCreateListPage' => $this->IsCreateListPage,
            'IsCreateContentPage' => $this->IsCreateContentPage,
            'AutoCreateHtmlType' => $this->AutoCreateHtmlType,
            'ItemOpenType' => $this->ItemOpenType,
            'ItemListOrderType' => $this->ItemListOrderType,
            'ItemPageSize' => $this->ItemPageSize,
            'ListPageSavePathType' => $this->ListPageSavePathType,
            'NeedCreateHtml' => $this->NeedCreateHtml,
            'EnableSubDomain' => $this->EnableSubDomain,
            'ConfigType' => $this->ConfigType,
            'IncrementalUpdatePages' => $this->IncrementalUpdatePages,
            'EnablePhone' => $this->EnablePhone,
            'EnablePad' => $this->EnablePad,
            'status' => $this->status,
        ]);

        $query->andFilterWhere(['like', 'NodeIdentifier', $this->NodeIdentifier])
            ->andFilterWhere(['like', 'ParentPath', $this->ParentPath])
            ->andFilterWhere(['like', 'arrChildID', $this->arrChildID])
            ->andFilterWhere(['like', 'NodeDir', $this->NodeDir])
            ->andFilterWhere(['like', 'ParentDir', $this->ParentDir])
            ->andFilterWhere(['like', 'NodeName', $this->NodeName])
            ->andFilterWhere(['like', 'Tips', $this->Tips])
            ->andFilterWhere(['like', 'Description', $this->Description])
            ->andFilterWhere(['like', 'NodePicUrl', $this->NodePicUrl])
            ->andFilterWhere(['like', 'Meta_Keywords', $this->Meta_Keywords])
            ->andFilterWhere(['like', 'Meta_Description', $this->Meta_Description])
            ->andFilterWhere(['like', 'Creater', $this->Creater])
            ->andFilterWhere(['like', 'Custom_Content', $this->Custom_Content])
            ->andFilterWhere(['like', 'ContentPageHtmlRule', $this->ContentPageHtmlRule])
            ->andFilterWhere(['like', 'ListPageHtmlRule', $this->ListPageHtmlRule])
            ->andFilterWhere(['like', 'ItemAspxFileName', $this->ItemAspxFileName])
            ->andFilterWhere(['like', 'RelateNode', $this->RelateNode])
            ->andFilterWhere(['like', 'RelateSpecial', $this->RelateSpecial])
            ->andFilterWhere(['like', 'DefaultTemplateFile', $this->DefaultTemplateFile])
            ->andFilterWhere(['like', 'ContainChildTemplateFile', $this->ContainChildTemplateFile])
            ->andFilterWhere(['like', 'UpLoadDirRule', $this->UpLoadDirRule])
            ->andFilterWhere(['like', 'LinkUrl', $this->LinkUrl])
            ->andFilterWhere(['like', 'Settings', $this->Settings])
            ->andFilterWhere(['like', 'IPLock', $this->IPLock])
            ->andFilterWhere(['like', 'ListPagePostFix', $this->ListPagePostFix])
            ->andFilterWhere(['like', 'CultureName', $this->CultureName])
            ->andFilterWhere(['like', 'SubDomain', $this->SubDomain]);

        return $dataProvider;
    }
}
